package com.cj.mobile.iabp.mvp.ui.activity;

import static com.jess.arms.utils.Preconditions.checkNotNull;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.cj.mobile.iabp.R;
import com.cj.mobile.iabp.app.utils.CommonUtils;
import com.cj.mobile.iabp.di.component.DaggerPatientBasicInfoComponent;
import com.cj.mobile.iabp.mvp.contract.PatientBasicInfoContract;
import com.cj.mobile.iabp.mvp.model.entity.PatientInfo;
import com.cj.mobile.iabp.mvp.presenter.PatientBasicInfoPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;

/**
 * Created on 2025/09/25 17:45
 * 患者基本信息
 *
 * @author Love_xie
 * module name is PatientBasicInfoActivity
 */
public class PatientBasicInfoActivity extends BaseActivity<PatientBasicInfoPresenter> implements PatientBasicInfoContract.View {
    /*----------------------------------------------------------------控件信息----------------------------------------------------------------*/
    @BindView(R.id.txvi_patientbasicinfo_secName)
    TextView txviSecName;                                                                           // 院区
    @BindView(R.id.txvi_patientbasicinfo_cnt)
    TextView txviCnt;                                                                               // 安装次数
    @BindView(R.id.txvi_patientbasicinfo_code)
    TextView txviCode;                                                                              // 登记号
    @BindView(R.id.txvi_patientbasicinfo_name)
    TextView txviName;                                                                              // 患者姓名
    @BindView(R.id.txvi_patientbasicinfo_height)
    TextView txviHeight;                                                                            // 身高
    @BindView(R.id.txvi_patientbasicinfo_weight)
    TextView txviWeight;                                                                            // 体重
    @BindView(R.id.txvi_patientbasicinfo_sex)
    TextView txviSex;                                                                               // 性别
    @BindView(R.id.txvi_patientbasicinfo_age)
    TextView txviAge;                                                                               // 年龄
    @BindView(R.id.txvi_patientbasicinfo_pd)
    TextView txviPd;                                                                                // 主要诊断
    @BindView(R.id.txvi_patientbasicinfo_sd)
    TextView txviSd;                                                                                // 次要诊断
    @BindView(R.id.txvi_patientbasicinfo_other)
    TextView txviOther;                                                                             // 其它诊断
    @BindView(R.id.txvi_patientbasicinfo_deptName)
    TextView txviDeptName;                                                                          // 所属科室
    @BindView(R.id.txvi_patientbasicinfo_area)
    TextView txviArea;                                                                              // 所属病房
    @BindView(R.id.txvi_patientbasicinfo_bedNo)
    TextView txviBedNo;                                                                             // 所属床位
    @BindView(R.id.txvi_patientbasicinfo_friends)
    TextView txviFriends;                                                                           // 患者联系人
    @BindView(R.id.txvi_patientbasicinfo_phone)
    TextView txviPhone;                                                                             // 联系人电话
    /*----------------------------------------------------------------业务信息----------------------------------------------------------------*/
    // 患者基本信息数据源
    private PatientInfo info;

    /**
     * 根据主题使用不同的颜色。
     * 如果想要纯透明，则需要重写此方法，返回值为 -1 即可。
     */
    public int useStatusBarColor() {
        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(android.R.color.white, typedValue, true);
        return typedValue.data;
    }

    /**
     * 将状态栏改为浅色模式(状态栏 icon 和字体会变成深色)
     */
    public boolean useLightStatusBar() {
        return true;
    }

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerPatientBasicInfoComponent
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_patient_basic_info;
    }

    public void getBundleValues(Bundle bundle) {
        // 获取默认值
        if (bundle != null) {
            info = bundle.getParcelable("info");
        }
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        setTitle("患者信息");

        getBundleValues(getIntent().getExtras());
        loadData();
    }

    private void loadData() {
        if (info != null) {
            txviSecName.setText(CommonUtils.isEmptyReturnStr(info.getSecName()));
            txviCnt.setText(CommonUtils.isEmptyReturnStr(info.getCnt()));
            txviCode.setText(CommonUtils.isEmptyReturnStr(info.getCode()));
            txviName.setText(CommonUtils.isEmptyReturnStr(info.getName()));
            txviHeight.setText(CommonUtils.isEmptyReturnStr(info.getHeight()));
            txviWeight.setText(CommonUtils.isEmptyReturnStr(info.getWeight()));

            if (TextUtils.isEmpty(info.getSex())) {
                txviSex.setText("");
            } else {
                if (info.getSex().equals("1")) {
                    txviSex.setText("男");
                } else if (info.getSex().equals("2")) {
                    txviSex.setText("女");
                } else {
                    txviSex.setText("其它");
                }
            }
            txviAge.setText(CommonUtils.isEmptyReturnStr(info.getAge()));
            txviPd.setText(CommonUtils.isEmptyReturnStr(info.getDiagnoseF()));
            txviSd.setText(CommonUtils.isEmptyReturnStr(info.getDiagnoseS()));
            txviOther.setText(CommonUtils.isEmptyReturnStr(info.getDiagnose()));
            txviDeptName.setText(CommonUtils.isEmptyReturnStr(info.getDeptName()));
            txviArea.setText(CommonUtils.isEmptyReturnStr(info.getArea()));
            txviBedNo.setText(CommonUtils.isEmptyReturnStr(info.getBedNo()));
            txviFriends.setText(CommonUtils.isEmptyReturnStr(info.getFriends()));
            txviPhone.setText(CommonUtils.isEmptyReturnStr(info.getPhone()));
        }
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
}